USE [Monitoring]
GO

--|--------------------------------------------------------------------------------
--| [GetUserToRoleByID] - Insert Procedure Script for UserToRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[GetUserToRoleByID]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[GetUserToRoleByID]
GO

CREATE PROCEDURE [dbo].[GetUserToRoleByID]
(
	@ID int
)
AS
	SET NOCOUNT ON

	SELECT
		[ID],
		[UserID],
		[UserRoleID]
	FROM 
UserToRole
	WHERE
		[ID] = @ID
	
GO


--|--------------------------------------------------------------------------------
--| [InsertUserToRole] - Insert Procedure Script for UserToRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[InsertUserToRole]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[InsertUserToRole]
GO

CREATE PROCEDURE [dbo].[InsertUserToRole]
(
	@ID int = NULL OUTPUT,
	@UserID int,
	@UserRoleID int
)
AS
	SET NOCOUNT ON

	INSERT INTO [UserToRole]
	(
		[UserID],
		[UserRoleID]
	)
	VALUES
	(
		@UserID,
		@UserRoleID
	)

	SELECT @ID = SCOPE_IDENTITY();

	RETURN @@Error
GO

--|--------------------------------------------------------------------------------
--| [UpdateUserToRole] - Update Procedure Script for UserToRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[UpdateUserToRole]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
	DROP PROCEDURE [dbo].[UpdateUserToRole]
GO

CREATE PROCEDURE [dbo].[UpdateUserToRole]
(
	@ID int,
	@UserID int,
	@UserRoleID int
)
AS
	SET NOCOUNT ON
	
	UPDATE [UserToRole]
	SET
		[UserID] = @UserID,
		[UserRoleID] = @UserRoleID
	WHERE 
		[ID] = @ID

	RETURN @@Error
GO

--|--------------------------------------------------------------------------------
--| [DeleteUserToRole] - Update Procedure Script for UserToRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[DeleteUserToRole]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
	DROP PROCEDURE [dbo].[DeleteUserToRole]
GO

CREATE PROCEDURE [dbo].[DeleteUserToRole]
(
	@ID int
)
AS
	SET NOCOUNT ON

	DELETE 
	FROM   [UserToRole]
	WHERE  
		[ID] = @ID

	RETURN @@Error
GO

